package com.yq.day30;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 09:25
 */
public class Demo02 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        FutureTask<Integer> f1 = new FutureTask<>(new MyCallable(200));
        FutureTask<Integer> f2 = new FutureTask<>(new MyCallable(100));
        Thread thread = new Thread(f1);
        Thread thread1 = new Thread(f2);
        thread.start();
        thread1.start();
        Integer integer = f1.get();
        Integer integer1 = f2.get();
        System.out.println(integer);
        System.out.println(integer1);


    }
}


class MyCallable implements Callable<Integer> {
    int number;

    public MyCallable(int number) {
        this.number = number;
    }

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 1; i <= number; i++) {
            sum += i;
        }
        return sum;
    }
}